//
//  imageTableViewCell.m
//  UI_wangyi
//
//  Created by dllo on 16/6/22.
//  Copyright © 2016年 HeyGirls. All rights reserved.
//

#import "imageTableViewCell.h"
#import "textModel.h"
#import "GetHeightTools.h"

@interface imageTableViewCell ()

@property (nonatomic, retain) UIImageView *upImageView;
@property (nonatomic, retain) UIImageView *downImageView;
@property (nonatomic, retain) UILabel *label;

@end

@implementation imageTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.upImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_upImageView];
        [_upImageView release];
        self.downImageView =  [[UIImageView alloc] init];
        [self.contentView addSubview:_downImageView];
        [_downImageView release];
        self.label = [[UILabel alloc] init];
        [self.contentView addSubview:_label];
        [_label release];
    }
    return self;
}

-(void)layoutSubviews {
    
    CGFloat labelHeight = [GetHeightTools heightWith:self.imageModel.digest];
    
    CGFloat imageHeight = [GetHeightTools twoHeightWith:self.imageModel.img];
    
    self.label.frame = CGRectMake(10, 10, self.contentView.bounds.size.width, labelHeight + 20);
    
    self.upImageView.frame = CGRectMake(0,labelHeight + 20, self.contentView.bounds.size.width, imageHeight + 20);
    // self.upImageView.backgroundColor = [UIColor orangeColor];
    
    self.downImageView.frame = CGRectMake(0, labelHeight + imageHeight + 20, self.contentView.bounds.size.width, 50);
    // self.downImageView.backgroundColor = [UIColor yellowColor];
    
    self.label.numberOfLines = 0;
    
}

-(void)setImageModel:(textModel *)imageModel {
    
    if (_imageModel != imageModel) {
        [_imageModel release];
        _imageModel = [imageModel retain];
    }
    
    self.label.text = imageModel.digest;
    
    NSURL *url = [NSURL URLWithString:imageModel.img];
    
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    UIImage *image = [UIImage imageWithData:data];
    
    self.upImageView.image = image;
    
    self.downImageView.image = [UIImage imageNamed:@"down"];
    
}

@end
